/**
 * @file {cf精度检测目标库panel表model}
 */
'use strict'

const { DataTypes, Model, Op } = require('../../../azeroth').sequelize;
class PanelJingdu extends Model { }

/**
 * @desc 映射需要的字段 【源库的 部分字段 --> 目标库字段】
 */
 const initData = (sequelize_aim) => {
    Panel.init(
        {
            uid: {
                field: 'uid',
                type: DataTypes.BIGINT(11) ,
                allowNull: false,
                primaryKey: true,
                autoIncrement: true,
            },
            panel_id: {
                field: 'panel_id',
                type: DataTypes.STRING,
            },
            gen_time_str: {
                field: 'gen_time_str',
                type: DataTypes.BIGINT,
            },
            is_ok: {
                field: 'is_ok',
                type: DataTypes.INTEGER,
            },
            save_path: {
                field: 'save_path',
                type: DataTypes.STRING,
            },
            lt_x: {
                field: 'lt_x',
                type: DataTypes.DOUBLE,
            },
            lt_y: {
                field: 'lt_y',
                type: DataTypes.DOUBLE,
            },
            lb_x: {
                field: 'lb_x',
                type: DataTypes.DOUBLE,
            },
            lb_y: {
                field: 'lb_y',
                type: DataTypes.DOUBLE(255, 12) ,
            },
            rb_x: {
                field: 'rb_x',
                type: DataTypes.DOUBLE,
            },
            rb_y: {
                field: 'rb_y',
                type: DataTypes.DOUBLE,
            },
            rt_x: {
                field: 'rt_x',
                type: DataTypes.DOUBLE,
            },
            rt_y: {
                field: 'rt_y',
                type: DataTypes.DOUBLE
            }
        },
        {
            freezeTableName: true,
            sequelize: sequelize_aim,
            modelName: 'panel',
            timestamps: false
        }
    )
 }

/**
 * 查询【最新】的一条panel的精度检测信息
 * @returns {Object} 查询的panel信息
 */
 PanelJingdu.findLatestPanelInfo = async (sequelize_source) => {
    let sql =  "select * from lami where uid = (select max(uid) from lami)";
    let res = await sequelize_source.query(sql, { type: sequelize_source.QueryTypes.SELECT });
    return res[0];
}
/**
 *上传到产线库
 * @param {Object} data 转换后上传的数据对象
 */
 PanelJingdu.uploadPanelInfo = async (data) => {
    let res = await PanelJingdu.create({...data});
    return res;
}

module.exports = {
    PanelJingdu,
    initData
};